﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAO
{
   public  class UserDao
    {
        public UserDao()
        {
            SqlHelper sql = new SqlHelper();
        }
        public DataTable getUsers(string name)
        {
            return SqlHelper.ExecuteDataTable("GET_USR", CommandType.StoredProcedure,
                "@FULL_NAME", name);
        }
        public bool insertUser(string username, string pass, string fullname, string admin)
        {
            return SqlHelper.ExecuteNonQuery("INSERT_USER", CommandType.StoredProcedure,
                "@USER_NAME", username,
                "@FULL_NAME", fullname,
                "@PASS", Encrypt.EncryptionToString(pass),
                "@ADMIN", admin);
        }
        public DataRow getUserById(int id)
        {
            DataTable tablle = SqlHelper.ExecuteDataTable("GET_USER_BY_ID", CommandType.StoredProcedure,
                "@ID", id);
            if (tablle != null)
            {
                return tablle.Rows[0];
            }
            else
                return null;
        }

        public bool changPassForUser(int id, string newpass, string fullName, string admin)
        {
            return SqlHelper.ExecuteNonQuery("CHANGE_PASS_FOR_USR", CommandType.StoredProcedure,
                "@ID", id,
                "@PASS", Encrypt.EncryptionToString(newpass),
                "@FULL_NAME", fullName,
                "@ADMIN", admin);
        }

        public bool changeAdminStatus(int id, string fullName, string admin)
        {
            return SqlHelper.ExecuteNonQuery("CHANGE_ADMIN_FOR_USR", CommandType.StoredProcedure,
                "@ID", id,
                "@FULL_NAME", fullName,
                "@ADMIN", admin);
        }

        public bool deleteUser(int id)
        {
            return SqlHelper.ExecuteNonQuery("DELETE_USER", CommandType.StoredProcedure,
                "@ID", id);
        }
    }
}
